package sparrowGui
{
	import flash.display.DisplayObject;
	import flash.display.DisplayObjectContainer;
	
	import sparrowGui.impl.IDispObjectModule;
	import sparrowGui.utils.EventDispatcherEx;
	import sparrowGui.utils.IEventDispatcherEx;
	import sparrowGui.utils.SparrowUtil;
	import sparrowGui.vars.GUICss;
	
	/**
	 * 基本模块,基本UI适配器
	 * 主要设计思路是初始的时间将皮肤放入,然后对皮肤显示对象增加控制的事件的操作.
	 * 就将插件一样,想给皮肤什么功能就用插件直接插上去.
	 * @author Pelephone
	 */
	public class BaseUIModule extends EventDispatcherEx implements IEventDispatcherEx,IDispObjectModule
	{
		private var _skin:DisplayObject;
		public function BaseUIModule(argSkin:DisplayObject=null)
		{
			_skin = argSkin;
			setAttrByVars();
			addListener();
		}
		
		/**
		 * 通过皮肤创建此组件
		 * @param argSkin
		 */
		public function create(argSkin:DisplayObject):void
		{
			_skin = argSkin;
			addListener();
		}

		public function get skin():DisplayObject
		{
			return _skin;
		}

		/**
		 * 单只改变皮肤,其它监听不变
		 * (要移除原先的皮肤监听和清对象,不然会回收不了)
		 * @param value
		 */
		public function changeSkin(value:DisplayObject):void
		{
			removeListener();
			_skin = value;
		}
		
		/**
		 * 通过默认包设置属性
		 * @param vars
		 */
		public function setAttrByVars():void
		{
			SparrowUtil.copyObject(this,GUICss.obj);
		}
		
		/**
		 * 增加监听
		 */
		public function addListener():void
		{
			
		}
		
		/**
		 * 移出监听
		 */
		public function removeListener():void
		{
			
		}
		
		//// 显示对象操作 //////////////////
		
		public function addToParent(parent:DisplayObjectContainer):void
		{
			parent.addChild(skin);
		}
		
		public function set height(value:Number):void
		{
			_skin.height = value;
		}
		
		public function get height():Number
		{
			return _skin.height;
		}
		
		public function set width(value:Number):void
		{
			_skin.width = value;
		}
		
		public function get width():Number
		{
			return _skin.width;
		}
		
		public function set x(value:Number):void
		{
			_skin.x = value;
		}
		
		public function get x():Number
		{
			return _skin.x;
		}
		
		public function set y(value:Number):void
		{
			_skin.y = value;
		}
		
		public function get y():Number
		{
			return _skin.y;
		}
	}
}